namespace utils {
    void ChkErr() {
        DWORD errCode = GetLastError();
        LPSTR msgBuf = nullptr;
        FormatMessageA(
            FORMAT_MESSAGE_ALLOCATE_BUFFER | FORMAT_MESSAGE_FROM_SYSTEM |
            FORMAT_MESSAGE_IGNORE_INSERTS,
            nullptr, errCode, MAKELANGID(LANG_NEUTRAL, SUBLANG_DEFAULT),
            reinterpret_cast<LPSTR>(&msgBuf), 0, nullptr
        );
        fprintf(stderr, "ERR %lu: %s\n", errCode, msgBuf);
        LocalFree(msgBuf);
    }
    template <typename Func, typename... Args>
    void stubborn(Func func, Args... args) {
        while (!func(args...)) ChkErr(), Sleep(50);
    }
}

using utils::stubborn;
